package com.autonavi.yunda.yunji.core.service.dbImpl;

import com.autonavi.yunda.yunji.core.service.ICommonTairService;
import com.autonavi.yunda.yunji.core.service.dbfactory.TairFactoryService;
import com.autonavi.yunda.yunji.core.service.dbhelper.TairHelper;
import com.taobao.tair.DataEntry;
import com.taobao.tair.ResultCode;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author cizhong.wcs
 * @date 2023/8/3 15:59
 */
@Component
public class CommonTairServiceImpl implements ICommonTairService {

    @Resource
    TairFactoryService tairFactoryService;

    @Override
    public ResultCode put(String dbName, String key, String value, int version, int expired) {
        TairHelper instance = tairFactoryService.getInstance(dbName);
        return instance.put(key, value, version, expired);
    }

    @Override
    public String get(String dbName, String key) {
        TairHelper instance = tairFactoryService.getInstance(dbName);
        return instance.get(key);
    }

    @Override
    public boolean invalid(String dbName, String key) {
        TairHelper instance = tairFactoryService.getInstance(dbName);
        return instance.invalid(key);
    }

    @Override
    public List<DataEntry> mget(String dbName, List<String> key) {
        TairHelper instance = tairFactoryService.getInstance(dbName);
        return instance.mget(key);
    }

    @Override
    public Map<String, Integer> mgetInt(String dbName, List<String> key) {
        TairHelper instance = tairFactoryService.getInstance(dbName);
        return instance.mgetInt(key);
    }

    @Override
    public int incTime(String dbName, String key, Integer expireTime) {
        TairHelper instance = tairFactoryService.getInstance(dbName);
        return instance.incTime(key, expireTime);
    }

    @Override
    public List<DataEntry> tairBatchGet(String dbName, List<String> keys, int groupSize) {
        TairHelper instance = tairFactoryService.getInstance(dbName);
        return instance.tairBatchGet(keys, groupSize);
    }
}
